package com.mycode.chapter05.valves;

import org.apache.catalina.*;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import java.io.IOException;

public class ClientIpLoggerValve implements Valve, Contained {

    protected Container container;

    @Override
    public String getInfo() {
        return null;
    }

    @Override
    public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException {
        System.out.println("enter ClientIpLoggerValve ");
        // 将此请求传递给管道中的下一个阀门
        context.invokeNext(request, response);
        System.out.println("Client IP Logger Valve");
        ServletRequest servletRequest = request.getRequest();
        System.out.println(servletRequest.getRemoteAddr());
        System.out.println(">>>>>>>>>>>> ClientIpLoggerValve <<<<<<<<<<<<<");
    }

    @Override
    public Container getContainer() {
        return container;
    }

    @Override
    public void setContainer(Container container) {
        this.container = container;
    }
}
